package org.budo.tencent.api;

import org.budo.support.http.client.HttpUtil;
import org.budo.support.http.client.Response;
import org.budo.tencent.response.MeResponse;
import org.budo.tencent.response.TokenResponse;

/**
 * @author lmw
 */
public class TencentOauthApi extends AbstractTencentApi {
    public MeResponse me(String accessToken) {
        String url = "https://graph.qq.com/oauth2.0/me" //
                + "?access_token=" + accessToken;

        Response response = HttpUtil.get(url);
        return new MeResponse(response);
    }

    public TokenResponse token(String code) {
        String url = "https://graph.qq.com/oauth2.0/token" //
                + "?grant_type=authorization_code" //
                + "&client_secret=" + this.getAppSecret() //
                + "&client_id=" + this.getAppKey() //
                + "&redirect_uri=" + this.getRedirectUri() //
                + "&code=" + code;

        Response response = HttpUtil.get(url);
        return new TokenResponse(response);
    }
}